package com.example.blog.controller;

import com.example.blog.entity.Blog;
import com.example.blog.entity.Result;
import com.example.blog.service.BlogService;
import org.apache.ibatis.annotations.Param;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("/markdown")
public class BlogController {

    @Resource
    private BlogService blogService;

    // 上传 或 更新 博客
    @PostMapping("/upload")
    public Result insertBlog(@RequestBody Blog blog){
        return blogService.insertBlog(blog);
    }

    // 根据分类 获取 标题
    @GetMapping("/getTitle")
    public Result getTitleByClassify(@Param("classify") String classify){
        return blogService.getTitleByClassify(classify);
    }
    // 根据标题获取博客内容
    @GetMapping("/getBlog")
    public Result getBlogByTitle(@Param("title") String title){
        return blogService.getBlogByTitle(title);
    }

    // 获取该用户博客的所有分类
    @GetMapping("/getClassify")
    public Result getClassify(){
        return blogService.getClassify();
    }

    // 删除博客
    @DeleteMapping("/delBlog")
    public Result delBlog(@Param("title") String title){
        return blogService.delBlog(title);
    }

}
